$(document).ready(function(){
    //type-ahead
    $("#GroupSearch").click(function(){
        this.value = '';
    });    
    
    //type-ahead
    $("#GroupSearch").autocomplete({
        source: function(request, response){
            $("#GroupProgress").show();
            $.ajax({
                type:'GET',url: $("#AjaxController").val() + "?api=GroupSearch&groupSearchString=" + request.term,
                dataType: "json",
                success: function( json ) {
                    $("#GroupProgress").hide();
                    response( $.map( json.DATA, function( n ) {//this is a auto returned variable.  jquery kungfu
                        return {value: n[1], id: n[0] }
                    }));
                }
            });
        },
        minLength: 3,
        delay: 0,
        select: function(event, ui){
            $("#GroupSearch").val(ui.item.value);
            $("#GroupDN").val(ui.item.id);          
           document.location.href = $('#ViewGroup').val() + ui.item.value;
        }
    });
    //type-ahead
    
    
    
    //type-ahead
    $("#UserSearch").click(function(){
        this.value = '';
    });    
    
    //type-ahead
    $("#UserSearch").autocomplete({
        source: function(request, response){
            $("#UserProgress").show();
            $.ajax({
                type:'GET',url: $("#AjaxController").val() + "?api=UserSearch&userSearchString=" + request.term,
                dataType: "json",
                success: function( json ) {
                    $("#UserProgress").hide();
                    response( $.map( json.DATA, function( n ) {//this is a auto returned variable.  jquery kungfu
                        return {value: n[6], id: n[0], url: n[1] }
                    }));
                }
            });
        },
        minLength: 3,
        delay: 0,
        select: function(event, ui){
            ajaxCompleted(event, ui);            
        }
    });
}); 


function ajaxCompleted(event, ui){
    $("#UserSearch").val(ui.item.value);
    $("#UserDN").val(ui.item.id);          
    document.location.href = $('#ViewUser').val() + ui.item.url;
    return false;    
}
